//
//  CustomNavBar.swift
//  Qianzoo
//
//  Created by franze on 2017/6/1.
//  Copyright © 2017年 franze. All rights reserved.
//

import UIKit

class CustomNavBar: UIView {
    var backBtn:UIButton!
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    func initialize(text:String?){
        backgroundColor = .white
        
        if let _text = text{
            let title = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 20))
            title.center = CGPoint(x: center.x, y: 42)
            title.textAlignment = .center
            title.textColor = UIColor.black
            title.font = UIFont.boldSystemFont(ofSize: 20)
            title.text = _text
            title.tag = 1
            addSubview(title)
        }
        
        backBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
        backBtn.center = CGPoint(x: 22, y: 42)
        backBtn.setImage(UIImage(named:"back")?.scaleImageToSize(CGSize(width: 14, height: 14)), for: .normal)
        backBtn.imageEdgeInsets = UIEdgeInsets(top: 13, left: 13, bottom: 13, right: 13)
        addSubview(backBtn)
        
        let line = CAShapeLayer()
        line.frame = CGRect(x: 0, y: bounds.height-1, width: WIDTH, height: 1)
        line.backgroundColor = UIColor.lightGray.cgColor
        layer.addSublayer(line)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
